// ==UserScript==
// @name       百度贴吧显示性别
// @namespace  http://cyanidea.com/
// @updateURL   https://git.oschina.net/lawrencecloud/test/raw/master/tieba_sex_show.meta.js
// @downloadURL https://git.oschina.net/lawrencecloud/test/raw/master/tieba_sex_show.user.js
// @version    0.1
// @description  应燕要求所制作的小脚本
// @include     http://tieba.baidu.com/p/*
// @copyright  2014, 123456789小子
// @grant       none
// @run-at document-end
// ==/UserScript==
addcss();
window.onload=run;
function run(){
    var posts=document.getElementsByClassName('l_post');
    var userdata;var sex;var sex_class;
    for(var i=0;i<posts.length;++i){
        sex=document.createElement('span');
        eval('userdata='+posts[i].getAttribute('data-field'));
        
        switch(userdata.author.user_sex){
            case 0:sex_class='';break;
            case 1:sex_class='sex_male';break;
            case 2:sex_class='sex_female';break;
        }
        sex.setAttribute('class', sex_class);
        posts[i].getElementsByClassName('d_name')[0].appendChild(sex);
    }
}
function addcss(){
    var sex_css=document.createElement('style');
    sex_css.type='text/css';
    sex_css.textContent='.sex_male{background:url(http://tb2.bdstatic.com/tb/static-ihome/img/icon_groups_26e15a2.png);background-position:0 -32px}.sex_female{background:url(http://tb2.bdstatic.com/tb/static-ihome/img/icon_groups_26e15a2.png);background-position:0 -63px}.d_name span{height:14px;width:14px;margin-left:4px;display:inline-block}';
    document.documentElement.appendChild(sex_css);
}